home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / memtest8.000 / memtest8 / memtest86 / setup.S < prev   
Encoding:
Text File  |  1996-05-29  |  3.0 KB  |  152 lines

  1. !
  2. ! setup.s is responsible for getting the system data from the BIOS,
  3. ! and putting them into the appropriate places in system memory.
  4. ! both setup.s and system has been loaded by the bootblock.
  5. !
  6. ! 1-Jan-96 Modified by Chris Brady for use as a boot/loader for memtest-86.
  7.  
  8. #include "mtest.h"
  9.  
  10. .globl begtext, begdata, begbss, endtext, enddata, endbss
  11. .text
  12. begtext:
  13. .data
  14. begdata:
  15. .bss
  16. begbss:
  17. .text
  18.  
  19. entry start
  20. start:
  21.  
  22. ! ok, the read went well so we get current cursor position and save it for
  23. ! posterity.
  24.  
  25.     mov    ax,#INITSEG    ! this is done in bootsect already, but...
  26.     mov    ds,ax
  27.  
  28. ! Get memory size (extended mem, kB)
  29.  
  30.         mov     ah,#0x88
  31.         int     0x15
  32.         mov     [0],ax
  33.  
  34. ! now we want to move to protected mode ...
  35.  
  36.     cli            ! no interrupts allowed !
  37.     mov    al,#0x80    ! disable NMI for the bootup sequence
  38.     out    #0x70,al
  39.  
  40. ! first we move the system to its rightful place
  41.  
  42.     mov    ax,#TESTSEG    ! start of destination segment
  43.     mov    bx,#TSTLOAD    ! start of source segment
  44.     cld            ! 'direction'=0, movs moves forward
  45. do_move:
  46.     mov    es,ax        ! destination segment
  47.     add    ax,#0x100
  48.     cmp    ax,#TESTSEG+TSTSIZE
  49.     jz    end_move
  50.     mov    ds,bx        ! source segment
  51.     add    bx,#0x100
  52.     sub    di,di
  53.     sub    si,si
  54.     mov     cx,#0x800
  55.     rep
  56.     movsw
  57.     jmp    do_move
  58.  
  59. ! then we load the segment descriptors
  60.  
  61. end_move:
  62.     push    cs
  63.     pop    ds
  64.     lidt    idt_48        ! load idt with 0,0
  65.     lgdt    gdt_48        ! load gdt with whatever appropriate
  66.  
  67. ! that was painless, now we enable A20
  68.  
  69.     call    empty_8042
  70.     mov    al,#0xD1        ! command write
  71.     out    #0x64,al
  72.     call    empty_8042
  73.     mov    al,#0xDF        ! A20 on
  74.     out    #0x60,al
  75.     call    empty_8042
  76.  
  77. ! Note that the short jump isn't strictly needed, althought there are
  78. ! reasons why it might be a good idea. It won't hurt in any case.
  79. !
  80.     mov    ax,#0x0001    ! protected mode (PE) bit
  81.     lmsw    ax        ! This is it!
  82.     jmp    flush_instr
  83. flush_instr:
  84.     mov    ax,#KERNEL_DS
  85.     mov    ds,ax
  86.     mov    ss,ax
  87.     mov    ax,#0x0720
  88.     mov    ebx,#0xb8000
  89.     mov    ecx,#0xc0000
  90. clrlp:
  91.     mov    (ebx),ax
  92.     inc    ebx
  93.     inc    ebx
  94.     cmp    ebx,ecx
  95.     jnz    clrlp
  96.  
  97.     jmpi    TESTADR,KERNEL_CS    ! jmp offset 2000 of segment 0x10 (cs)
  98.  
  99. ! This routine checks that the keyboard command queue is empty
  100. ! (after emptying the output buffers)
  101. !
  102. ! No timeout is used - if this hangs there is something wrong with
  103. ! the machine, and we probably couldn't proceed anyway.
  104. empty_8042:
  105.     call    delay
  106.     in    al,#0x64    ! 8042 status port
  107.     test    al,#1        ! output buffer?
  108.     jz    no_output
  109.     call    delay
  110.     in    al,#0x60    ! read it
  111.     jmp    empty_8042
  112. no_output:
  113.     test    al,#2        ! is input buffer full?
  114.     jnz    empty_8042    ! yes - loop
  115.     ret
  116. !
  117. ! Delay is needed after doing i/o
  118. !
  119. delay:
  120.     .word    0x00eb            ! jmp $+2
  121.     ret
  122.  
  123. gdt:
  124.     .word    0,0,0,0        ! dummy
  125.  
  126.     .word    0,0,0,0        ! unused
  127.  
  128.     .word    0x7FFF        ! limit 128mb
  129.     .word    0x0000        ! base address=0
  130.     .word    0x9A00        ! code read/exec
  131.     .word    0x00C0        ! granularity=4096, 386
  132.  
  133.     .word    0x7FFF        ! limit 128mb
  134.     .word    0x0000        ! base address=0
  135.     .word    0x9200        ! data read/write
  136.     .word    0x00C0        ! granularity=4096, 386
  137.  
  138. idt_48:
  139.     .word    0            ! idt limit=0
  140.     .word    0,0x3            ! idt base=0L
  141.  
  142. gdt_48:
  143.     .word    0x800        ! gdt limit=2048, 256 GDT entries
  144.     .word    512+gdt,0x9    ! gdt base = 0X9xxxx
  145.  
  146. .text
  147. endtext:
  148. .data
  149. enddata:
  150. .bss
  151. endbss:
  152.